package com.albert.order.mq;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Component;

/**
 * @author yangjunwei
 * @date 2021/7/12 10:02 上午
 */
@Slf4j
@Component
public class MqProducer {

    @Autowired
    private JmsTemplate jmsTemplate;

    @Value("${scheduleMsg.topic}")
    private String scheduleMsgTopic;

    /**
     * 发送延时消息
     *
     * @param orderId 数据
     * @param delay   延时时间
     */
    public void scheduleSnedMsg(Integer orderId, long delay) {
        log.info("producer send msg =>{}", orderId);
        jmsTemplate.convertAndSend(scheduleMsgTopic, orderId, new ScheduleMessagePostProcesser(delay));
    }


}
